package com.basic.modules.ykf.controller;

import java.util.Arrays;

import cn.hutool.core.util.ObjectUtil;
import com.basic.common.annotation.StringTrim;
import com.basic.common.exception.RRException;
import com.basic.common.utils.ParamsModel;
import com.basic.common.validator.ValidatorUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.basic.modules.ykf.entity.YkfLibraryManageEntity;
import com.basic.modules.ykf.service.YkfLibraryManageService;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.R;



/**
 * 文库管理
 *
 * @author maoheng
 * @email 15738859597@163.com
 * @date 2024-05-13 18:21:12
 */
@RestController
@RequestMapping("ykf/libraryManage")
public class YkfLibraryManageController {

    @Autowired
    private YkfLibraryManageService ykfLibraryManageService;

    /**
     * 列表-分页
     */
    @StringTrim
    @PostMapping("/page")
    public R list(@RequestBody ParamsModel<YkfLibraryManageEntity> params){
        PageUtils page = ykfLibraryManageService.queryPage(params);
        return R.ok(page);
    }


    /**
     * 信息
     */
    @PostMapping("/info")
    public R info(@RequestBody YkfLibraryManageEntity params){
        if (ObjectUtil.isEmpty(params) || ObjectUtil.isEmpty(params.getLibraryManageId())) {
            throw new RRException("参数缺失");
        }
        return R.ok(ykfLibraryManageService.getById(params.getLibraryManageId()));
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody YkfLibraryManageEntity ykfLibraryManage){
        ValidatorUtils.validateEntity(ykfLibraryManage);
		ykfLibraryManageService.save(ykfLibraryManage);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody YkfLibraryManageEntity ykfLibraryManage){
        ValidatorUtils.validateEntity(ykfLibraryManage);
		ykfLibraryManageService.updateById(ykfLibraryManage);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] libraryManageIds){
		ykfLibraryManageService.removeByIds(Arrays.asList(libraryManageIds));
        return R.ok();
    }

}
